<?php

/**
 * 这是一个表 "line_detail" 的模型类。
 *
 * 表 'line_detail' 有以下字段:
 * @property integer $id
 * @property integer $ad_id
 * @property integer $car_id
 * @property string $go_time
 * @property integer $position_id
 * @property integer $staff
 *
 * 以下是表的关联关系:
 * @property Staff $staff0
 * @property ActivityDetail $ad
 * @property Carinfo $car
 * @property Position $position
 */
class LineDetail extends CActiveRecord
{
	/**
	 * @return string 表名
	 */
	public function tableName()
	{
		return 'line_detail';
	}

	/**
	 * @return array 表字段验证规则的数组。
	 */
	public function rules()
	{
		return array(
                        array('car_id,go_time,position_id,staff', 'required'),
			array('ad_id, car_id, position_id, staff', 'numerical', 'integerOnly'=>true),
			array('go_time', 'safe'),
			// 以下规则用于验证查询函数，如果不做查询可注释此行。
			array('id, ad_id, car_id, go_time, position_id, staff', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array 关联关系。
	 */
	public function relations()
	{
		return array(
			'staff0' => array(self::BELONGS_TO, 'Staff', 'staff'),
			'ad' => array(self::BELONGS_TO, 'ActivityDetail', 'ad_id'),
			'car' => array(self::BELONGS_TO, 'Carinfo', 'car_id'),
			'position' => array(self::BELONGS_TO, 'Position', 'position_id'),
		);
	}

	/**
	 * @return array 自定义字段显示文本标签 (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '序号',
			'ad_id' => '活动明细',
			'car_id' => '车辆',
			'go_time' => '上车时间',
			'position_id' => '上车地点',
			'staff' => '随车人员',
		);
	}

	/**
	 * 自定义查询函数
	 * @return CActiveDataProvider 一个包含分页排序查询数据
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('ad_id',$this->ad_id);
		$criteria->compare('car_id',$this->car_id);
		$criteria->compare('go_time',$this->go_time,true);
		$criteria->compare('position_id',$this->position_id);
		$criteria->compare('staff',$this->staff);
		$criteria->order='id desc';//排序字段

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
                'pageSize'=>Yii::app()->params['pagesize'],//配置文件中设置过分页条数
            ),
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return LineDetail the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
